<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>pref管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../css/theme-chalk.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">

    <div class="content-header">
        <h1>管理
            <small>pref管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>管理</el-breadcrumb-item>
            <el-breadcrumb-item>pref管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <!--查询表单-->
                <el-form :inline="true">
                    <el-form-item label="分类ID">
                        <el-input v-model="searchMap.cateId" placeholder="分类ID" class="filter-item"></el-input>
                    </el-form-item>
                    <el-form-item label="消费金额">
                        <el-input v-model="searchMap.buyMoney" placeholder="消费金额" class="filter-item"></el-input>
                    </el-form-item>
                    <el-form-item label="优惠金额">
                        <el-input v-model="searchMap.preMoney" placeholder="优惠金额" class="filter-item"></el-input>
                    </el-form-item>
                    <el-form-item label="活动开始日期">
                        <el-input v-model="searchMap.startTime" placeholder="活动开始日期" class="filter-item"></el-input>
                    </el-form-item>
                    <el-form-item label="活动截至日期">
                        <el-input v-model="searchMap.endTime" placeholder="活动截至日期" class="filter-item"></el-input>
                    </el-form-item>
                    <el-form-item label="类型">
                        <el-input v-model="searchMap.type" placeholder="类型" class="filter-item"></el-input>
                    </el-form-item>
                    <el-form-item label="状态">
                        <el-input v-model="searchMap.state" placeholder="状态" class="filter-item"></el-input>
                    </el-form-item>

                    <el-button class="dalfBut" @click="fetchData()">查询</el-button>
                    <el-button type="primary" class="butT" @click="formVisible=true;pojo={}">新增</el-button>
                </el-form>
            </div>

            <el-table :data="tableData" border style="width: 100%">
                <el-table-column prop="id" label="ID" width="80"></el-table-column>
                <el-table-column prop="cateId" label="分类ID" width="80"></el-table-column>
                <el-table-column prop="buyMoney" label="消费金额" width="80"></el-table-column>
                <el-table-column prop="preMoney" label="优惠金额" width="80"></el-table-column>
                <el-table-column prop="startTime" label="活动开始日期" width="80"></el-table-column>
                <el-table-column prop="endTime" label="活动截至日期" width="80"></el-table-column>
                <el-table-column prop="type" label="类型" width="80"></el-table-column>
                <el-table-column prop="state" label="状态" width="80"></el-table-column>

                <el-table-column
                        label="操作">
                    <template slot-scope="scope">
                        <el-button @click="edit(scope.row.id)" size="mini" type="primary" size="small">修改</el-button>
                        <el-button @click="dele(scope.row.id)" size="mini" type="danger" size="small">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @size-change="fetchData"
                        @current-change="fetchData"
                        :current-page.sync="currentPage"
                        :page-sizes="[10, 20, 30, 40]"
                        :page-size="size"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
            <div class="add-form">
                <!--弹出窗口-->
                <el-dialog title="编辑" :visible.sync="formVisible">
                    <el-form label-width="80px">
                        <el-form-item label="分类ID">
                            <el-input v-model="pojo.cateId"></el-input>
                        </el-form-item>
                        <el-form-item label="消费金额">
                            <el-input v-model="pojo.buyMoney"></el-input>
                        </el-form-item>
                        <el-form-item label="优惠金额">
                            <el-input v-model="pojo.preMoney"></el-input>
                        </el-form-item>
                        <el-form-item label="活动开始日期">
                            <el-input v-model="pojo.startTime"></el-input>
                        </el-form-item>
                        <el-form-item label="活动截至日期">
                            <el-input v-model="pojo.endTime"></el-input>
                        </el-form-item>
                        <el-form-item label="类型">
                            <el-input v-model="pojo.type"></el-input>
                        </el-form-item>
                        <el-form-item label="状态">
                            <el-input v-model="pojo.state"></el-input>
                        </el-form-item>


                        <el-form-item>
                            <el-button type="primary" @click="save()">保存</el-button>
                            <el-button @click="formVisible = false">关闭</el-button>
                        </el-form-item>
                    </el-form>
                </el-dialog>
            </div>

        </div>
    </div>


</div>
</body>
<script src="/js/vue.js"></script>
<script src="/js/axios.js"></script>
<script src="/js/elementui.js"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                tableData: [],
                currentPage: 1,
                total: 10,
                size: 10,
                searchMap: {},
                pojo: {},
                formVisible: false,
                imageUrl: ''
            }
        },
        created() {
            this.fetchData();
        },
        methods: {
            fetchData() {
                axios.post(`/pref/findPage.do?page=${this.currentPage}&size=${this.size}`, this.searchMap).then(response => {
                    this.tableData = response.data.rows;
                    this.total = response.data.total;
                });
            },
            save() {
                // this.pojo.image= this.imageUrl; //如页面有图片上传功能放开注释
                axios.post(`/pref/${this.pojo.id == null ? 'add' : 'update'}.do`, this.pojo).then(response => {
                    this.fetchData(); //刷新列表
                    this.formVisible = false;//关闭窗口
                });
            },
            edit(id) {
                this.formVisible = true // 打开窗口
                // 调用查询
                axios.get(`/pref/findById.do?id=${id}`).then(response => {
                    this.pojo = response.data;
                    // this.imageUrl=this.pojo.image //显示图片  如页面有图片上传功能放开注释
                })
            },
            dele(id) {
                this.$confirm('确定要删除此记录吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get(`/pref/delete.do?id=${id}`).then(response => {
                        this.fetchData(); //刷新列表
                    })
                })
            },
        }
    })
</script>
</html>
